<template>
  <el-container>
    <el-aside width="200px">
      <SideMenu></SideMenu>
    </el-aside>
    <el-container>
      <el-header>
        <strong>智慧小巷后台管理系统</strong>
        <div class="header-avatar">
          <el-avatar :src="userInfo.avatar"></el-avatar>
          <el-dropdown>
            <span class="el-dropdown-link">
              {{ userInfo.username }}
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <router-link to="/userCenter">个人中心</router-link>
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
        <Tabs></Tabs>
        <div style="margin: 0 20px">
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import SideMenu from '@/views/inc/SideMenu'
import Tabs from '@/views/inc/Tabs'

export default {
  name: 'Home',
  components: {
    SideMenu,
    Tabs,
  },
  data() {
    return {
      userInfo: {
        id: '',
        username: '',
        avatar: '',
      },
    }
  },
  created() {
    this.getUserInfo()
  },
  methods: {
    getUserInfo() {
      // this.$axios.get('/sys/userInfo').then((res) => {
      //   this.userInfo = res.data.data
      // })
      this.userInfo = this.$store.getters.getUserInfo
    },
    logout() {
      this.$axios.get('/logout').then((res) => {
        localStorage.clear()
        sessionStorage.clear()

        this.$store.commit('resetState')
        this.$router.push('/login')
      })
    },
  },
}
</script>

<style scoped>
.header-avatar {
  float: right;
  width: 120px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.el-dropdown-link {
  cursor: pointer;
  color: white;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.el-container {
  padding: 0;
  margin: 0;
  height: 100vh;
}

.el-header {
  background-color: rgb(113, 174, 223);
  color: white;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: left;
  line-height: 200px;
}

.el-main {
  color: #333;
  padding: 0;
}

a {
  text-decoration: none;
}
</style>